Xbasic

json_reformat Function

Syntax

C formatedJSON = json_reformat(jsonText as C [, indented as L ])

Arguments

jsonTextCharacter

The JSON text to format. The JSON must be properly formed.

indentedLogical

Default value is .t.. Defines whether or not the JSON should be indented. If .f., the JSON be generated on a single line with no line breaks or indentation.

Description

Takes json and reformats it so that it is presented on one line or extended to include multiple lines.

Discussion

The json_reformat function only accepts 'properly formed' JSON strings (property names must be double quoted and string values must be double quoted).

Example

dim json as c 
json = <<%txt%
{"firstname":"Fred",
"lastname":"Smith",
"Address":
{"Street":"123 Main St",
"City":"Boston",
"State":"Ma"}
}
%txt%

? json_reformat(json)
= {
    "firstname": "Fred",
    "lastname": "Smith",
    "Address": {
        "Street": "123 Main St",
        "City": "Boston",
        "State": "Ma"
    }
}

See Also